<template>
  <div id="" class="activityItem" @click="toMatchDetail(matchItem.id)">
    <span class="activityImg">
      <img :src="imgUrlLink(matchItem.themeIcon)" alt="">
      <em>{{getCreateTime(matchItem.createTime)}}</em>
    </span>
    <div class="activityDiv">
      <div class="activityTit">
        <h3>{{matchItem.title}}</h3>
        <span class="start">{{matchStatus()}}</span>
      </div>
      <div class="">
        <p>
          <img src="@/assets/activityImage/time_green3.png" alt="" width="15">
          {{matchItem.startBegin}}
        </p>
        <p>
          <img src="@/assets/activityImage/add_blue3.png" alt="" width="15">
          {{matchItem.activityAddr}}
        </p>
        <p>
          报名截止：{{matchItem.enrollEnd}}
        </p>
        <p>
          报名人数：18/{{matchItem.activityNo}} &nbsp;&nbsp;
          收费：&yen;{{matchItem.cost}}
        </p>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "",
  props: ['matchItem'],
  data: () => ({

  }),
  methods: {
    // 图片地址拼接
    imgUrlLink(imgUrl) {
      return this.$imgUrlLink(imgUrl);
    },
    // 创建时间
    getCreateTime(time) {
      let todaytime = new Date();   //当前时间
      let createTime = new Date(time);
      console.log(todaytime.getTime());
      let desTime = todaytime.getTime()/1000 - createTime.getTime()/1000;
      if (desTime<60) {
        if(desTime<0) desTime = 1;
        return Math.floor(desTime)+'秒前';
      }else if (desTime<3600) {
        let mm = Math.floor(desTime/ 60 % 60);
        return mm + '分钟前'
      }else if (desTime<(3600*24)) {
        let hh = Math.floor(desTime/3600);
        return hh + '小时前'
      }else{
        let dd = Math.floor(desTime/(3600*24));
        return dd + '天前'
      }
    },
    // 赛事状态
    matchStatus() {
        let todaytime = new Date().getTime();   //当前时间
        let enrollBegin = new Date(this.matchItem.enrollBegin).getTime();   //报名开始时间
        let enrollEnd = new Date(this.matchItem.enrollEnd).getTime();       //报名结束时间
        let startBegin = new Date(this.matchItem.startBegin).getTime();     //活动开始时间
        let startEnd = new Date(this.matchItem.startEnd).getTime();         //活动结束时间
        if(todaytime>enrollBegin && todaytime<enrollEnd){
          return "报名中"
        }else if(todaytime>startBegin && todaytime<startEnd){
          return "已开始"
        }else if(todaytime>enrollEnd && todaytime<startBegin){
          return '报名结束';
        }else if(todaytime>startEnd){
          return '已结束';
        }
    },
    // 跳转到赛事详情
    toMatchDetail(matchId) {
      this.$router.push({path:'/eventDetail',query:{matchId:matchId}});
    }
  }
}
</script>
<style lang="scss" scoped>
.activityItem{
  @include flex;
  align-items: flex-start;
  background: white;
  padding: 10px;
  margin-bottom: 6px;
  .activityImg{
    width: 110px;
    img{
      width: 100%; height: 80px;
    }
    em{
      margin-top: 6px;
      color: $lightColor;
      font-size: 12px;
    }
  }
  .activityDiv{
    @include flexcell;
    margin-left: 10px;
    @include flex;
    align-items: flex-start;
    flex-direction: column;
    justify-content: space-between;
    .activityTit{
      @include flex;
      justify-content: space-between;
      margin-bottom: 6px;
      h3{
        width: 178px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      span{
        color: $blueColor;
        &.start{
          color: $redColor;
        }
      }
    }
    p{
      color: $lightColor;
      font-size: 12px;
      margin-bottom: 4px;
    }
  }
}
</style>
